class PackagesController < ApplicationController
  before_action :set_menu

  def index
    @submenu = :package
    @title = '套餐管理'
    @packages = Package.all
  end

  def new
    @package = Package.new
  end

  def create
    @package = Package.new post_params
    if @package.save
      redirect_to packages_path
    else
      render :action => 'new'
    end
  end

  def edit
    @package = Package.find params[:id]
  end

  def update
    @package = Package.find params[:id]
    if @package.update_attributes post_params
      redirect_to packages_path
    else
      render :action => 'edit'
    end
  end

  def destroy
    @package = Package.find params[:id]
    @package.destroy
    redirect_to packages_path
  end

  def show
    @title = "套餐管理/明细"
    @buttons.push :action => packages_path, :label => "返回"
    @package = Package.find params[:id]
  end


  def post_params
    params.require(:package).permit(*%w(name))
  end

  private
  def set_menu
    @mainmenu = :base_data
  end
end
